using System;
using System.Collections.Generic;
using FluentNHibernate.Automapping;
using FluentNHibernate.Cfg;
using Environment = NHibernate.Cfg.Environment;

namespace NHibernateInsight.Tests.Infrastructure.Data
{
    public class SqlLiteDatabaseUsageStrategy : DatabaseUsageStrategyBase
    {
        public SqlLiteDatabaseUsageStrategy()
            : base(DefaultDatabaseName)
        {
        }

        public static string DefaultDatabaseName
        {
            get
            {
                return ":memory:";
            }
        }

        public override void PrepareDatabaseMedia()
        {
            // Nothing to do, by configuring the session factory 
            // correctly the database does it itself!
        }

        public override void DropDatabaseMedia()
        {
            // Nothing to do, by configuring the session factory 
            // correctly the database does it itself!
        }

        public override IDictionary<string, string> ConfigurationProperties
        {
            get
            {
                var properties = new Dictionary<string, string>();
                properties.Add(Environment.ConnectionDriver, "NHibernate.Driver.SQLite20Driver");
                properties.Add(Environment.Dialect, "NHibernate.Dialect.SQLiteDialect");
                properties.Add(Environment.ConnectionProvider, "NHibernate.Connection.DriverConnectionProvider");
                properties.Add(Environment.ConnectionString, string.Format("Data Source={0};Version=3;New=True;",
                                                                           DatabaseName));
                properties.Add(Environment.ShowSql, "true");
                properties.Add(Environment.ReleaseConnections, "on_close");
                properties.Add(Environment.ProxyFactoryFactoryClass, "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle");
                return properties;
            }
        }

    }
}